package org.gensokyo.crawler

import java.util.UUID

import org.apache.commons.codec.digest.DigestUtils
import sun.misc.BASE64Encoder

/**
  * Created by liusen on 17-2-15.
  */
package object luoli {

  def stripSpace(x: String) = x.replaceAll("""[ \n]+""", " ")

  def getEmailTail = {
    math.round(math.random * 7.0) match {
      case 0 => "qq.com"
      case 1 => "163.com"
      case 2 => "126.com"
      case 3 => "sina.com"
      case 4 => "yahoo.com"
      case 5 => "gmail.com"
      case 6 => "hotmail.com"
      case _ => "eyou.com"
    }
  }

  def getUserInfo = {
    val username = java.util.Base64.getEncoder.encodeToString(DigestUtils.md5Hex(UUID.randomUUID().toString).getBytes)
      .replaceAll("""[^\p{Alnum}]""", "").substring(0, (math.round(math.random * 3.0) + 10).toInt)
    val password = java.util.Base64.getEncoder.encodeToString(DigestUtils.md5Hex(UUID.randomUUID().toString).getBytes)
      .replaceAll("""[^\p{Alnum}]""", "").substring(0, (math.round(math.random * 3.0) + 10).toInt)
    val email = s"""${username.substring(1, username.length - 2)}@${getEmailTail}"""
    (username, password, email)
  }
}
